<template>
  <div class="c-form-padding">
    <el-form
      :model="caseForm"
      ref="caseForm"
      :rules="caseRules"
      label-width="150px"
      :inline="false"
    >
      <el-form-item label="承办单位" prop="">
        <el-input
          style="width: 500px"
          v-model="caseForm.undertake_dept_name"
          disabled
        ></el-input>
      </el-form-item>
      <el-form-item label="办理时间" prop="">
        <el-date-picker
          v-model="caseForm.solve_date"
          type="date"
          value-format="yyyy-MM-dd"
          disabled
        >
        </el-date-picker>
      </el-form-item>
      <!-- <label class="rg-label">党委（党组）主体责任</label>
      <div class="responsible-group">
        <el-form-item label="责任单位" prop="responsible_dept_id">
          <DeptCascader
            :options="dept"
            :defaultChecked.sync="caseForm.responsible_dept_id"
            @change="changeDept"
          ></DeptCascader>
        </el-form-item>
        <el-form-item label="处置建议" prop="responsible_proposal">
          <el-input
            type="textarea"
            v-model="caseForm.responsible_proposal"
            :autosize="{
              minRows: 3,
              maxRows: 6,
            }"
          ></el-input>
        </el-form-item>
        <el-form-item label="附件" prop="">
          <CommonUpload
            tableName="oneCaseThreeCheck"
            useType="dwcz"
            :pid="detail.assign_id"
          ></CommonUpload>
        </el-form-item>
      </div> -->
      <!-- <label class="rg-label">纪委（纪检机构）党建责任</label> -->
      <!-- <label class="rg-label">党建责任</label>
      <div class="responsible-group">
        <el-form-item label="责任单位" prop="supervise_dept_id">
          <el-select v-model="caseForm.supervise_dept_id">
            <el-option
              v-for="item in dcDept"
              :key="item.value"
              :label="item.dept_name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="处置建议" prop="supervise_proposal">
          <el-input
            type="textarea"
            v-model="caseForm.supervise_proposal"
            :autosize="{
              minRows: 3,
              maxRows: 6,
            }"
          ></el-input>
        </el-form-item>
        <el-form-item label="附件" prop="">
          <CommonUpload
            tableName="oneCaseThreeCheck"
            useType="jwcz"
            :pid="detail.assign_id"
          ></CommonUpload>
        </el-form-item>
      </div> -->
      <!-- <el-form-item label="纪检室审核意见" prop="disciplinary_opinion">
        <el-input
          type="textarea"
          v-model="caseForm.disciplinary_opinion"
          :autosize="{
            minRows: 3,
            maxRows: 6,
          }"
        ></el-input>
      </el-form-item>
      <el-form-item label="纪检室审核时间" prop="disciplinary_optime">
        <el-date-picker
          v-model="caseForm.disciplinary_optime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="分管领导审核意见" prop="leader_opinion">
        <el-input
          type="textarea"
          v-model="caseForm.leader_opinion"
          :autosize="{
            minRows: 3,
            maxRows: 6,
          }"
        ></el-input>
      </el-form-item>
      <el-form-item label="分管领导审核时间" prop="leader_optime">
        <el-date-picker
          v-model="caseForm.leader_optime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期时间"
        >
        </el-date-picker>
      </el-form-item> -->
      <el-form-item label="一案三查处理结果" prop="">
        <PunishFormForOCTC
          :punishList.sync="caseForm.fourForms"
        ></PunishFormForOCTC>
      </el-form-item>
      <el-form-item label="">
        <el-button type="primary" @click="save">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getCurrentDate } from "@/utils/date";
import DeptCascader from "@/components/Common/DeptCascader.vue";
import { getDeptTree } from "@/api/System/Department";
import { getUndertakeDept, postOneCaseThreeCheck } from "@/api/RedAlert/Index";
import CommonUpload from "@/components/Common/CommonUpload.vue";
import PunishFormForOCTC from "./PunishFormForOCTC.vue";

export default {
  components: { DeptCascader, CommonUpload, PunishFormForOCTC },
  props: {
    detail: {
      type: Object,
      default: null,
    },
  },
  data() {
    return {
      caseForm: {
        warning_id: 0, // 预警ID
        warning_assign_solve_id: "", // 预警处置ID
        undertake_dept_name: "", // 承办单位名称
        undertake_dept_id: "", // 承办单位id
        solve_date: getCurrentDate(), // 办理时间
        // ----- 党委（党组）主体责任 -----
        responsible_proposal: "", // 主体责任单位处置建议
        responsible_dept_name: "", // 责任单位
        responsible_dept_id: "", // 责任单位ID
        // ----- 纪委（纪检机构）的监督责任 -----
        supervise_proposal: "", //  处置建议
        supervise_dept_name: "", // 责任单位
        supervise_dept_id: "", // 责任单位ID
        disciplinary_opinion: "", // 纪检室审核意见
        disciplinary_optime: "", // 纪检室审核意见时间
        leader_opinion: "", // 分管领导审核意见
        leader_optime: "", // 分管领导审核时间
        fourForms: [], // 处理结果
      },
      caseRules: {},
      dept: [],
      dcDept: [],
      dialog: {
        punishResult: false,
      },
    };
  },
  methods: {
    changeDept(val) {
      this.caseForm.responsible_dept_id = val.value;
      this.caseForm.responsible_dept_name = val.label;
    },
    initDept() {
      getDeptTree().then((res) => {
        if (res.code == 0) {
          this.dept = res.data;
        }
      });
      getUndertakeDept().then((res) => {
        if (res.code == 0) {
          this.dcDept = res.data;
        }
      });
    },
    save() {
      this.$refs.caseForm.validate((valid) => {
        if (valid) {
          // this.caseForm.supervise_dept_name = this.dcDept.filter((i) => {
          //   if (i.id == this.caseForm.supervise_dept_id) {
          //     return i;
          //   }
          // })[0].dept_name;

          this.caseForm.warning_id = this.detail.id;
          this.caseForm.warning_assign_solve_id = this.detail.assign_id;

          postOneCaseThreeCheck(this.caseForm).then((res) => {
            if (res.code == 0) {
              this.$message.success("保存成功");
              this.$emit("refresh");
            }
          });
        }
      });
    },
  },
  created() {
    let user = JSON.parse(localStorage.getItem("user"));
    this.caseForm.undertake_dept_name = user.dept_name;
    this.caseForm.undertake_dept_id = user.dept_id;

    this.initDept();
  },
};
</script>

<style lang="scss" scoped>
.rg-label {
  font-size: 18px;
  line-height: 36px;
  font-weight: 600;
}
.responsible-group {
  border: 1px solid #ccc;
  border-radius: 15px;
  box-sizing: border-box;
  padding: 20px 20px 20px 0;
  margin: 10px 0;
}
</style>